﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using hStatsC.Helper;
using Panuon.UI.Silver;
using PropertyChanged;

namespace hStatsC
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    public partial class MainWindow : Window
    {
        public bool LoginMode { get; set; }
        public string username { get; set; } 
        public string password { get; set; } 

        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            LoginMode = true;
        }

        private void Btn_Login(object sender, RoutedEventArgs e)
        {
            try
            {
                if (MainHelper.Login(username, password))
                {
                    //登入成功
                    new DashboardView().Show();
                    this.Close();
                }
                else
                {
                    MessageBoxX.Show($"登入失败!\n请核对用户名{username}及密码", "失败");
                }
            }
            catch (Exception exception)
            {
                MessageBoxX.Show($"hStats服务器可能状态异常了!\n详细问题:{exception.Message}", "异常");
            }
        }

        private void Btn_ChangePageMode(object sender, RoutedEventArgs e)
        {
            LoginMode = !LoginMode;
        }


        private void Btn_Reg(object sender, RoutedEventArgs e)
        {
            try
            {
                if (MainHelper.Reg(username, pwd: password))
                {
                    MessageBoxX.Show($"注册成功!\n用户名:{username}\n已经为你转为登入页面!", "成功");
                    LoginMode = true;
                }
                else
                {
                    MessageBoxX.Show($"注册失败!\n用户名:{username}\n可能已经存在", "失败");
                }
            }
            catch (Exception exception)
            {
                MessageBoxX.Show($"hStats服务器可能状态异常了!\n详细问题:{exception.Message}", "异常");
            }
        }
    }
}